package a_aa_amainpackage.lvyou_clear.lv_update.util

import com.alibaba.fastjson.JSON
import org.apache.spark.SparkContext
import org.apache.spark.sql.{DataFrame, SQLContext, SparkSession}
import org.elasticsearch.spark._

/*
*项目名: o2odata_commend
*文件名: update_address
*创建者: hancongcong
*创建时间:2020/2/4 12:12
*描述: TODO
*/ object update_address {
//  val month ="3"

  /**
    * 更新分类
    * @param sc
    * @param sqlContext
    * @param month
    */
  def cately(frame1:DataFrame,sc:SparkContext,sqlContext:SQLContext,month:String):DataFrame = {
    //2019_update_tuniu_mp/tuniu_mp_2019_11
//    val data = sc.esJsonRDD(s"2021_update_tuniu_ly/tuniu_ly_2021_${month}").values
//    travelType_hotelInfo(sqlContext.sparkSession,sqlContext.read.json(data)).filter("travel_type='自助游'").show()
    travelType_hotelInfo(sqlContext.sparkSession,frame1)
//    toes()
  }

  def toes(data: DataFrame,month:String): Unit = {
    val value = data.toJSON.rdd.map(line => {
      val lines = JSON.parseObject(line)
      lines
    })
    value.saveToEs(s"2021_update_tuniu_ly/tuniu_ly_2021_${month}", Map("es.mapping.id" -> "product_Id"))
  }
  def  travelType_hotelInfo(spark: SparkSession, dataFrame: DataFrame): DataFrame = {
    dataFrame.withColumnRenamed("travel_type", "travel_type_old").createOrReplaceTempView("dataTable_hotel")
    val sql =
      s"""
         |
         |select
         |*,
         |case
         |when travel_type_old = '跟团游' then '跟团游'
         |when travel_type_old = '私家团' then '跟团游'
         |when travel_type_old = '游学团' then '跟团游'
         |when travel_type_old = '多日游' then '跟团游'
         |
         |when travel_type_old = '自由行' then '自助游'
         |when travel_type_old = '半自助游' then '自助游'
         |when travel_type_old = '一日游' then '自助游'
         |when travel_type_old rlike '半自助游' then '自助游'
         |
         |when travel_type_old rlike "参团" then '跟团游'
         |when travel_type_old rlike "团" then '跟团游'
         |when travel_type_old rlike "游学" then '跟团游'
         |else '跟团游' end travel_type,
         |
         |
         |case
         |when lodging_info rlike '豪华型' then '5'
         |when lodging_info rlike '高档型' then '4'
         |when lodging_info rlike '品质型' then '4'
         |when lodging_info rlike '舒适型' then '3'
         |when lodging_info rlike '经济型' then '2'
         |when lodging_info rlike '简约型' then '2'
         |when lodging_info rlike '五星级' then '5'
         |when lodging_info rlike '四星级' then '4'
         |when lodging_info rlike '三星级' then '3'
         |when lodging_info rlike '二星级' then '2'
         |when lodging_info rlike '豪华' then '5'
         |when lodging_info rlike '高档' then '4'
         |when lodging_info rlike '品质' then '4'
         |when lodging_info rlike '舒适' then '3'
         |when lodging_info rlike '经济' then '2'
         |when lodging_info rlike '简约' then '2'
         |when lodging_info rlike '五星' then '5'
         |when lodging_info rlike '四星' then '4'
         |when lodging_info rlike '三星' then '3'
         |when lodging_info rlike '二星' then '2'
         |else '-1' end hotel_star,
         |case
         |when lodging_info rlike '豪华型' then '豪华型酒店'
         |when lodging_info rlike '高档型' then '高档型酒店'
         |when lodging_info rlike '品质型' then '高档型酒店'
         |when lodging_info rlike '舒适型' then '舒适型酒店'
         |when lodging_info rlike '经济型' then '经济型酒店'
         |when lodging_info rlike '简约型' then '经济型酒店'
         |when lodging_info rlike '五星级' then '豪华型酒店'
         |when lodging_info rlike '四星级' then '高档型酒店'
         |when lodging_info rlike '三星级' then '舒适型酒店'
         |when lodging_info rlike '二星级' then '经济型酒店'
         |when lodging_info rlike '豪华' then '豪华型酒店'
         |when lodging_info rlike '高档' then '高档型酒店'
         |when lodging_info rlike '品质' then '高档型酒店'
         |when lodging_info rlike '舒适' then '舒适型酒店'
         |when lodging_info rlike '经济' then '经济型酒店'
         |when lodging_info rlike '简约' then '经济型酒店'
         |when lodging_info rlike '五星' then '豪华型酒店'
         |when lodging_info rlike '四星' then '高档型酒店'
         |when lodging_info rlike '三星' then '舒适型酒店'
         |when lodging_info rlike '二星' then '经济型酒店'
         |else '-1' end hotel_grade
         |
         |from
         |dataTable_hotel
       """.stripMargin

    spark.sql(sql).drop("travel_type_old")
  }




}
